package com.li.service;

import java.util.List;

import com.li.Dao.UserDao;
import com.li.hibernate.pojo.ShUser;
import com.li.util.PageBean;

public class UserService {

	private UserDao userDao;

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}
	
	
	
	public ShUser findByUsername(String username){
		return userDao.findByUsername(username);
	}

	
	public void save(ShUser user) {
		
		userDao.save(user);
		
	}

	public ShUser login(ShUser user) {
		return userDao.login(user);
	}

	
	public PageBean<ShUser> findByPage(Integer page) {
		PageBean<ShUser> pageBean = new PageBean<ShUser>();
		
		pageBean.setPage(page);
		
		int limit = 5;
		pageBean.setLimit(limit);
		int totalCount = 0;
		totalCount = userDao.findCount();
		pageBean.setTotalCount(totalCount);
		
		int totalPage = 0;
		if(totalCount % limit == 0){
			totalPage = totalCount / limit;
		}else{
			totalPage = totalCount / limit + 1;
		}
		pageBean.setTotalPage(totalPage);
		
		int begin = (page - 1)*limit;
		List<ShUser> list = userDao.findByPage(begin,limit);
		pageBean.setList(list);
		return pageBean;
	}


	public ShUser findByUid(Integer uid) {
		return userDao.findByUid(uid);
	}

	
}
